<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%
    /************************查询科室*******************************/
    String parent = input.getDesc("parent", "-1");
    Integer branch = input.getInt("branch", -1);
    Integer type = input.getInt("type", DEPT_ALL);  // 不传默认科室介绍DEPT_ALL
    String selectContent = "new map(id as id , deptId as dept_id, deptName as dept_name, parent as parent, branch as branch, branchName as branch_name, type as type)";
    Where where  = new Where();
    if (branch != -1) {
        where.and("branch=", branch);
    }
    where.and("type=", type);
    List<Map> list = QBuilder.db("basedb").select(selectContent).from("Dept").where(where.and("hospital=", hospital).and("status = ", STATUS_ENABLE)).order("hospitalOrder", "asc").query().getResultObj();
    if (list.size() == 0) {
        msg = new Message(30041, "没有相关数据");
        msg.put("data", "");
    } else {

    }
    List<Map> list1 = new ArrayList<Map>();
    List<Map> list2 = new ArrayList<Map>();
    String branch1 = "";
    String branchName = "";
    String branchName2 = "";
    String branch2 = "";
    for(Map map : list)
    {
        String bch = map.get("branch").toString();


        if("01".equals(bch)){
            branch1 = bch;
            branchName = map.get("branch_name").toString();
            list1.add(map);
        }else{
            branch2 = bch;
            branchName2 = map.get("branch_name").toString();
            list2.add(map);
        }
    }
    List<Map> listAll = new ArrayList<Map>();
    Map map = new HashMap();
    map.put("branch",branch1);
    map.put("branch_name",branchName);
    map.put("depts",list1);

    Map map2 = new HashMap();
    map2.put("branch",branch2);
    map2.put("branch_name",branchName2);
    map2.put("depts",list2);
    listAll.add(map2);
    listAll.add(map);

    msg.put("data", listAll);
    Tools.encryptPrint(out,msg);
%>
